<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https=>//www.hyperf.io
 * @document https=>//hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https=>//github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller\Admin;

use App\Constants\ErrorCode;
use Hyperf\HttpServer\Annotation\Controller;
use Core\Repository\Admin\UserRepository;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use App\Middleware\AdminAuthMiddleware;
use App\Middleware\LoginAuthMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Exception\BussniessException;

/**
 * SiteController
 * 不需要权限验证的控制器
 * @package App\Controller\Admin
 * @Controller(prefix="/site")
 * @Middlewares({
 *     @Middleware(LoginAuthMiddleware::class)
 * })
 * @property \Core\Repository\Admin\PermissionRepository $permissionRepo
 * @property \Core\Repository\Admin\MenuRepository $menuRepo
 */
class SiteController extends BaseController
{
    /**
     * getroutes
     * 获取用户权限对应的菜单
     * @return \Psr\Http\Message\ResponseInterface
     * @GetMapping(path="getroutes")
     */
    public function getroutes()
    {
        $list = $this->menuRepo->getUserMenuList();
        $data = [
            'list' => $list
        ];

        return $this->response->success($data);
    }

    /**
     * getPermissions
     * 获取权限列表，创建菜单需要配置权限
     * @return \Psr\Http\Message\ResponseInterface
     *
     * @GetMapping(path="permissions_list")
     */
    public function getPermissions()
    {
        $list = $this->permissionRepo->getAllPremission();

        $data = [
            'list' => $list
        ];

        return $this->response->success($data);
    }
}
